#include "btoken.h"
#include <stdio.h>

/*
	TOKEN_KEYWORD = 0,
	TOKEN_VARNAME,      // asdf
	TOKEN_NUMBER,       // 1234, 0x1234, 01234
	TOKEN_STRING,		// "~~~~~~"
	TOKEN_OPERATOR,		// +, -, *, <, <=, ==, >=, >, !=, =, and, or, xor
	TOKEN_LPAREN,		// (
	TOKEN_RPAREN,		// )
	TOKEN_SEPERATOR	
*/


void PrintToken(Token* token, int tokenn) {
	int i;
	const char* ttstr[] = {
		"TOKEN_KEYWORD",
		"TOKEN_VARNAME",
		"TOKEN_NUMBER",
		"TOKEN_STRING",
		"TOKEN_OPERATOR",
		"TOKEN_LPAREN",
		"TOKEN_RPAREN",
		"TOKEN_SEPERATOR"
	};

	printf("Start dumping : \n");
	for(i = 0 ; i < tokenn ; i++) {
		printf(" token %d dumping : %.*s\n", i, token[i].m_end - token[i].m_begin, token[i].m_begin);
	}
}

int main() {
	while(1) {
		Token* tok;
		int tokenn;

		char str[512];
		printf("expr << ");
		gets(str);
		tok = TokenizeLine(str, &tokenn);
		if(tok == NULL) {
			printf("tokenize failed.\n");
			continue;
		}

		printf("tokenize result for %s : \n", str);
		PrintToken(tok, tokenn);
	}
	return 0;
}